package controleur;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import application.Consts;

import modele.CKModel;
import modele.Knowledge;
import vue.VueEditeurCK;

public class ControleAddKnowledge implements ActionListener {

	CKModel<String, String> _modele;
	VueEditeurCK _vue;

	public ControleAddKnowledge(CKModel<String, String> modele, VueEditeurCK vue) {
		_modele = modele;
		_vue = vue;
	}

	public void actionPerformed(ActionEvent e) {
		Knowledge<String> knowledge = new Knowledge<String>(_modele.getKSpace()
				.size(), _vue.getPanelAddK().getTextK());
		_modele.addKnowledge(knowledge);

		if (_vue.getPanelAddK().getRdbK().isSelected()) {
			_modele.addLink(_modele.findConceptFromId(_vue.getPanelAddK()
					.getCmbC().getSelectedIndex()), _modele.getKSpace()
					.elementAt(_modele.getKSpace().size() - 1));
		}

		_vue.getEditorFrame().remove(_vue.getPanelAddK());
		_vue.getEditorFrame().add(_vue.getPanelC(), BorderLayout.NORTH);

		_vue.getEditorFrame().paint(_vue.getEditorFrame().getGraphics());
		if (_vue.getVisumode() == Consts.VisualizationMode.TEXT) {
			_vue.getPanelT().updateAllTextAreas();
		}
		_vue.dessiner();

	}

}
